﻿<!--
Elements show other products of product have alias $product_alias

Elements params:
- $category_alias	: 	alias of category (todo: try to automatic get category_alias from product_alias)
- $product_alias		:	alias of product
-->

<?php
	if(!isset($category_alias)) {
		$product_categories = ClassRegistry::init('products.ProductCategory')->find('first', array(
			'conditions'	=> array('ProductCategory.alias <>'	=> 'root'),
			'fileds'	=> array('id', 'name', 'alias'),
			'contain'	=>false
		));
		$category_alias = 
	} 

	$other_products = ClassRegistry::init('products.Product')->find('all', array(
		'conditions'	=> array(
			'ProductCategory.alias'	=> $category_alias,
			'Product.alias <>'			=> $product_alias,
			'is_published'   		=> 1
		),
		'fields'	=> array('Product.id', 'Product.alias', 'Product.title', 'Product.created', 'Product.description', 'Product.image'),
		'contain'	=> array(),
		'limit'		=> 4,
		'order'		=> 'Product.created desc',
		'joins' => array(
			array(
				'table' => 'products_middle',
				'type' => 'INNER',
				'alias' => 'ReferenceCategory',
				'conditions' => array(
					"Product.id = ReferenceCategory.page_id"
				)
			),
			array(
				'table' => 'product_categories',
				'type' => 'INNER',
				'alias' => 'ProductCategory',
				'conditions' => array(
					"ProductCategory.id = ReferenceCategory.category_id"
				)
			)
		),
		
	));
?>

<h2><?php __("Những tin khác"); ?></h2>
<ul class="news-entries">
<?php foreach($other_products as $other_new): ?>
    <li>
        <h4><a href="<?php echo $html->url(array('plugin' => 'products', 'controller' => 'products', 'action' => 'view', $other_new['Product']['alias'], $category_alias));?>"><?php echo $other_new['Product']['title']; ?></a></h4>
        <a href="<?php echo $html->url(array('plugin' => 'products', 'controller' => 'products', 'action' => 'view', $other_new['Product']['alias'], $category_alias));?>"><?php echo $html->image('/files/products/'.$html->getThumbnailName($other_new['Product']['image']), array("alt"=>"Image", "class"=>"img-news")) ?></a>
        <p><?php echo substr(strip_tags($other_new['Product']['description']),0 ,160);?></p>
    </li>
<?php endforeach; ?>
</ul>